﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dictionaries.aspx.cs" Inherits="ValuationClient.系统管理.Dictionaries" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic DataGrid - jQuery EasyUI Demo</title>
    <link href="../jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="../jquery-easyui-1.5.2/themes/icon.css" rel="stylesheet" />
    <link href="../jquery-easyui-1.5.2/demo/demo.css" rel="stylesheet" />
    <script src="../js/jquery-1.8.2.min.js"></script>
    <script src="../jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
    <script src="../jquery-easyui-1.5.2/easyloader.js"></script>
    <script src="../js/jquery.params.js"></script>
</head>
<body>
    <!----查询字典信息---->
    <div>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="margin-bottom: 2px; margin-right: 10px;" onclick="newuser()">添加字典</a>
        <select class="easyui-combobox" style="width:150px;" id="type1" ></select>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width: 80px; margin-bottom: 2px;" onclick="show()">查询</a>
    </div>
    <!----显示字典信息---->
    <div style="width: 58%; height: 100%; margin: 10px;">
        <table id="dg" class="easyui-datagrid" title="字典信息显示">
        </table>
    </div>
    <!----弹出框---->
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: 200px; padding: 10px 20px; text-align: center"
        closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" action="">
            <div class="fitem">
                <label id="m">
                    编号：
                </label>
                <input name="dictionary_Id" class="easyui-validatebox" required id="dictionary_num" />
            </div>
            <br />
            <div class="fitem">
                <label>
                    字典名称：</label>
                <input name="dictionary_Name" class="easyui-validatebox" required id="Dictionary_Name" />
            </div>
            <br />
            <input type="hidden" name="action" id="hidtype" />
            <input type="hidden" name="roles_Id" id="Nameid" />
        </form>
    </div>
    <div id="dlg-buttons">
        <a class="easyui-linkbutton" onclick="saveuser()" iconcls="icon-save" id="upd">修改</a>
        <a class="easyui-linkbutton" iconcls="icon-save" id="save">保存</a>
        <a class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')" iconcls="icon-cancel">取消</a>
    </div>
</body>
</html>
 <script>
     $(function () {
         show();
         ShowDic();
     })
     //动态加载数据
     function show() {
         //var t = $('#type1').combobox('getText');

         $.ajax({
             type: "get",
             url: "http://localhost:55439/api/Values/GetDictionary",
             dataType: "json",
             success: function (obj) {
                 obj = eval(obj);

                 $("#dg").datagrid({

                     columns: [[
                     { field: 'dictionary_Id', width: 150, title: '编号', align: 'center', closed: true, },
                     { field: 'dictionary_Name', width: 150, align: 'center', title: '字典名称' },
                     { field: 'dictionary_Type', width: 150, align: 'center', title: '字典类型' },
                     { field: '_operate', width: 158, align: 'center', formatter: formatOper, title: '操作' },
                         //标题    
                     ]]
                 });
                 $("#dg").datagrid("loadData", obj);  //动态取数据
             }
         })
     }

     //下拉框绑定
     function ShowDic() {
         $.ajax({
             type: "get",
             url: "http://localhost:55439/api/Values/ShowDic",
             dataType: "json",
             success: function (obj) {
                 obj = eval(obj);

                 $("#type1").combobox({
                     data: obj,
                     valueField: 'value',
                     textField: 'text',
                 })
             }
         })
     }

     //添加自定义删除修改按钮
     function formatOper(val, row, index) {
         return '<a href="#" onclick="editUser(' + index + ')">修改</a>&nbsp;&nbsp;<a href="#" onclick="DelRole(' + index + ')">删除</a>';
     }

     //显示弹出框
     function editUser(index) {
         $("#save").hide();
         $('#dg').datagrid('selectRow', index);// 关键在这里  
         var row = $('#dg').datagrid('getSelected');
         if (row) {
             $('#dlg').dialog('open').dialog('setTitle', '修改字典信息');
             $('#fm').form('load', row);
         }
     }

     //修改字典
     function saveuser() {

         var dictionary_Id = $("#dictionary_num").val();
         var dictionary_Name = $("#Dictionary_Name").val();

         $.ajax({
             type: "post",
             url: 'http://localhost:55439/api/Values/DicUpdSysDictionary',
             data: { dictionary_Id: dictionary_Id, dictionary_Name: dictionary_Name },
             success: function (result) {
                 alert(result);
                 if (result == true) {
                     $.messager.alert("提示信息", "操作成功");
                     $("#dlg").dialog("close");
                     show();
                 }
                 else {
                     $.messager.alert("提示信息", "操作失败");
                 }
             }
         })
     }

     //删除字典
     function DelRole(index) {
         $('#dg').datagrid('selectRow', index);
         var row = $('#dg').datagrid('getSelected');
         if (row) {
             $.ajax({
                 type: "post",
                 url: 'http://localhost:55439/api/Values/DicDelSysDictionary?id=' + row.dictionary_Id,


                 success: function (result) {
                     alert(result);
                     if (result == true) {
                         $.messager.alert("提示信息", "操作成功");
                         $("#dlg").dialog("close");
                         show();
                     }
                     else {
                         $.messager.alert("提示信息", "操作失败");
                     }
                 }
             })
         }
     }

     //添加字典
     function newuser() {

         var type1 = $('#type1').combobox('getValue');

         if (type1 == 0) {
             $.messager.alert("提示信息", "请选择字典类型");
         }
         else {
             $("#dlg").dialog("open").dialog('setTitle', '添加字典信息');;
             $("#fm").form("clear");
             $("#dictionary_num").hide();
             $("#m").hide();
             $("#upd").hide();
             $("#save").on("click",
                 function () {
                     var dictionary_Name = $("#Dictionary_Name").val();
                     var dictionary_Type = $('#type1').combobox('getText');
                     $.ajax({
                         type: "post",
                         url: 'http://localhost:55439/api/Values/DicAddSysDictionary',
                         data: { dictionary_Name: dictionary_Name, dictionary_Type: dictionary_Type },
                         success: function (result) {
                             alert(result);
                             if (result == true) {
                                 $.messager.alert("提示信息", "操作成功");
                                 $("#dlg").dialog("close");
                                 show();
                             }
                             else {
                                 $.messager.alert("提示信息", "操作失败");
                             }
                         }
                     })
                 }
                 )
         }
     }

    </script>


      
